<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>
<body>
	<!-- <script src="call&apply&bind.js" type="text/javascript"></script> -->
	<script type="text/javascript">
		function Parent(){ // 构造函数
			this.name = 'zxw';
			this.age = '666';
			this.show = function(){
				console.log(this.name,this.age)
			}
		}
		Parent.prototype.name = '原型对象111' // 原型
		let parent1 = new Parent() // 实例对象
		console.log(Parent.prototype === parent1.__proto__)
		Parent.prototype = {a:666}
		/*
		实例对象创建在重写原型对象之前，则实例指向的__proto__指向重写后的原型对象
		实例对象创建在重写原型对象之后，则实例对象的原型指向最初的原型对象，
		*/
		console.log(parent1.constructor)
		console.log(parent1 instanceof Parent)
		console.log(Parent.prototype === parent1.__proto__)
		console.log(Object.getPrototypeOf(parent1))


		function fun(){this.name = 666}
		fun.prototype = {    
		    name : 'peter',    
		    age : 25    
		}
		var a = new fun();
		var b = new fun();
		fun.prototype.name = 'jack';
		console.log(a.name, b.name);//jack jack
		fun.prototype = {};
		fun.prototype.name = 'tom';
		console.log(a.name, b.name); //jack jack
		console.log('重写之后的原型对象：',fun.prototype)
		/*
		重写之后的原型对象是new Object().__proto__ = {},而不是函数的prototype属性，所以，b.constructor指向的是Object的构造函数；而上边的第一个例子,虽然也经过了重写原型对象，但是是在实例化对象之后重写的，所以parent1.constructor指向的是构造函数Parent,
		*/
		console.log('1',b.constructor === fun)  //1 false
		console.log('2',b instanceof fun)  //2 false
		b.constructor.prototype.name = 'kitty'; //b.constructor.prototype指向的是fun的prototype
		console.log(a.name, b.name); //jack jack
	</script>
</body>
</html>